package recycle.impl;

import org.springframework.stereotype.Service;
import recycle.dao.ApplepropertieschooseMapper;
import recycle.pojo.Applepropertieschoose;
import recycle.service.ApplepropertieschooseService;
import recycle.utils.Page;
import recycle.vo.ApplepropertieschooseParam;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
* 描述：苹果属性选择表 服务实现层接口
* @author 孙冉
* @date 2019/07/22
*/
@Service
public class ApplepropertieschooseServiceImpl implements ApplepropertieschooseService{
	@Resource
	private ApplepropertieschooseMapper applepropertieschooseMapper;
 	
 	/**
    * 描述：根据Id获取Applepropertieschoose对象
    * @param id
    */
    public Applepropertieschoose findById(Serializable chooseId){
    	return applepropertieschooseMapper.findById(chooseId);
    }
    /**
    * 描述：获取所有的Applepropertieschoose对象
    */
    public List<Applepropertieschoose> findAll(){
    	return applepropertieschooseMapper.findAll();
    }

	/**
    * 描述：新增保存Applepropertieschoose对象
    */
    public int save(Applepropertieschoose applepropertieschoose){
    	return  applepropertieschooseMapper.save(applepropertieschoose);
    }

	/**
    * 描述：根据Id删除Applepropertieschoose对象
    * @param id
    */
    public int delete(Serializable chooseId){
    	return  applepropertieschooseMapper.delete(chooseId);
    }
	
	/**
    * 描述：更新Applepropertieschoose对象
    */
    public int update(Applepropertieschoose applepropertieschoose){
    	return  applepropertieschooseMapper.update(applepropertieschoose);
    }
    
    /**
     * 根据不确定的条件，动态查询
     */
    public List<Applepropertieschoose> query(ApplepropertieschooseParam param){
    	return  applepropertieschooseMapper.query(param);
    }
    
    /**
     * 根据不确定的条件，动态分页查询
     */
    public Page queryByPage(ApplepropertieschooseParam param){
    	Page page = new Page();
    	if(param.isPage()){
			int totalCount = applepropertieschooseMapper.getCount(param);
			int totalPageCount = (totalCount-1)/page.getPageSize()+1;
			if(param.getPageIndex()<1){
				param.setPageIndex(1);
			}else if(param.getPageIndex()>totalPageCount){
				param.setPageIndex(totalPageCount);
			}
			List list = applepropertieschooseMapper.query(param);

			page.setTotalCount(totalCount);
			page.setTotalPageCount(totalPageCount);
    		page.setPageNo(param.getPageIndex());
    		page.setPageSize(param.getSize());
			page.setList(list);
		}
    	return page;
    	
    }

}
